package com.tech.koufu.ui.adapter;

import com.tech.koufu.ui.view.CompetitionContentFragment;
import com.tech.koufu.ui.view.ExpertsContentFragment;
import com.tech.koufu.ui.view.HomeContainerFragment;
import com.tech.koufu.ui.view.MarketContentFragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.util.Log;
import android.view.ViewGroup; 

public class HomePagerAdapter extends FragmentStatePagerAdapter {
	private static final String TAG = HomePagerAdapter.class.getName();
	public int cc;
	public int count = 4;
	private Fragment home,experts,mcf,ccf;

	public HomePagerAdapter(FragmentManager fm) {
		super(fm);
	}
	@Override
	public Fragment getItem(int postion) { 
		if(postion==0){ 
			if(home!=null){Log.w(TAG, "~~~~~~0~~~~~~~~");
				return home;
			}Log.w(TAG, "~~~~~~00~~~~~~~~");
			home = new HomeContainerFragment();
			return home;
		}else if (postion==1){
			if(experts==null){Log.w(TAG, "~~~~~~1~~~~~~~~");
				experts = new ExpertsContentFragment();
			}Log.w(TAG, "~~~~~~11~~~~~~~~");
			return experts;
		}else if(postion==3){
			if(ccf==null){Log.w(TAG, "~~~~~~3~~~~~~~~");
				ccf = new CompetitionContentFragment();
			}Log.w(TAG, "~~~~~~33~~~~~~~~");
			return ccf;
		} else if(postion==2){
			if(mcf==null){Log.w(TAG, "~~~~~~2~~~~~~~~");
				mcf = new MarketContentFragment();
			}Log.w(TAG, "~~~~~~22~~~~~~~~");
			return mcf;
		} 
		return null;
	}

	@Override
	public int getCount() { 
		return count;
	}
	@Override
	public Object instantiateItem(ViewGroup viewGroup, int position) {
		return super.instantiateItem(viewGroup, position);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		super.destroyItem(container, position, object);
	}

}